income <- read.csv("data/income.csv")
income <- income |>
mutate(
Average_Income = as.integer(Average_Income),
ClassLabel = factor(
paste0(Class, " | $",
format(Average_Income,
big.mark = ",")
),
levels = unique(paste0(Class, " | $",
format(Average_Income,
big.mark = ",")))
)
) |>
pivot_longer(
cols = Rent:Other, ## list slice-like syntax to get the ordered columns
names_to = "Category",
values_to = "Percent"
) |>
mutate(
Category = factor(Category,
levels = c("Other",
"Tax",
"Clothes",
"Food",
"Rent")),
text_color = ifelse(Category == "Rent",
"white",
"black")
) |>
group_by(ClassLabel) |>
mutate(pos = cumsum(Percent) - Percent / 2) |>
ungroup()
category_colors <- c(
Rent = "black",
Food = "slateblue4",
Clothes = "rosybrown2",
Tax = "gray60",
Other = "tan"
)
glimpse(income)
Rows: 35
Columns: 7
$ Class <chr> "$100-200", "$100-200", "$100-200", "$10…
$ Average_Income <int> 139, 139, 139, 139, 139, 249, 249, 249, …
$ ClassLabel <fct> "$100-200 | $ 139", "$100-200 | $ 139"…
$ Category <fct> Rent, Food, Clothes, Tax, Other, Rent, F…
$ Percent <dbl> 19.0, 43.0, 28.0, 9.9, 0.1, 22.0, 47.0, …
$ text_color <chr> "white", "black", "black", "black", "bla…
$ pos <dbl> 9.50, 40.50, 76.00, 94.95, 99.95, 11.00,…